package com.gko.file;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;


/**
 * Utility class for the file operations.
 * @author gheorghi.kozlovskii
 * */
public class FileOperations {

	private static Charset encoding = StandardCharsets.UTF_8;

	public static Charset getEncoding() {
		return encoding;
	}

	public static void setEncoding(Charset encoding) {
		FileOperations.encoding = encoding;
	}

	public static List<String> readSmallTextFile(String aFileName) throws IOException {
		Path path = Paths.get(aFileName);
		return Files.readAllLines(path, encoding);
	}

	public static List<String> readSmallTextFile(final String pathToFile,
			boolean exitOnException, String errorMessage) {
		
		List<String> retVal = null;
		
		try {
			retVal = readSmallTextFile(pathToFile);
		} catch (IOException e) {
			
			System.out.print(errorMessage);
			
			if (exitOnException) {
				System.exit(1);
			}
		}
		return retVal;
	}

}
